package com.ssy.lingxi.product.controller.pc;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.product.api.model.request.PriceCurveSetBatchRequest;
import com.ssy.lingxi.product.api.model.response.PriceCurveSetResponse;
import com.ssy.lingxi.product.service.IPriceCurveSetService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu: 价格曲线设置
 * @author jw.chen
 * @version 2.0.0
 * @date 2021/10/20
 */
@RestController
@RequestMapping("/product/priceCurveSet")
public class PriceCurveSetController extends BaseController {

    @Resource
    private IPriceCurveSetService priceCurveSetService;

    /**
     * 查询价格曲线设置列表
     * @return 价格曲线设置列表
     */
    @RequestMapping(value = "/getPriceCurveSetList", method = RequestMethod.GET)
    public Wrapper<List<PriceCurveSetResponse>> getPriceCurveSetList() {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(priceCurveSetService.getPriceCurveSetList(sysUser));
    }

    /**
     * 查询是否显示价格曲线
     * @param commodityId 商品id
     * @return 是/否显示
     */
    @RequestMapping(value = "/getIsShowPriceCurve", method = RequestMethod.GET)
    public Wrapper<Boolean> getIsShowPriceCurve(@RequestParam("commodityId") Long commodityId) {
        Long shopId = this.getHeadersShopId();
        return Wrapper.success(priceCurveSetService.getPriceCurveSet(shopId, commodityId));
    }

    /**
     * 新增价格曲线设置
     * @param priceCurveSetBatchRequest 参数实体
     * @return 是否设置成功
     */
    @RequestMapping(value = "/savePriceCurveSet", method = RequestMethod.POST)
    public Wrapper<Boolean> savePriceCurveSet(@RequestBody @Valid PriceCurveSetBatchRequest priceCurveSetBatchRequest){
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(priceCurveSetService.savePriceCurveSet(sysUser, priceCurveSetBatchRequest.getPriceCurveSetList()));
    }

}
